package zdream.pmfield.stage.message;

import java.util.Arrays;
import java.util.Map;
import java.util.Objects;

import zdream.pmfield.stage.director.StageResult;

/**
 * @author Zdream
 * @date 2023-11-15
 * @since 0.0.1
 */
public class StageFinishedMessage extends StageMessage {
	public final StageResult result;

	public StageFinishedMessage(StageResult result) {
		this.type = StageMessageType.REPORT;
		this.result = Objects.requireNonNull(result);
	}

	@Override
	public String toString() {
		final int[] successSides = result.sideResultMap.entrySet().stream()
				.filter(entry -> StageResult.StageResultType.SUCCESS.equals(entry.getValue()))
				.mapToInt(Map.Entry::getKey)
				.toArray();
		final int[] drawSides = result.sideResultMap.entrySet().stream()
				.filter(entry -> StageResult.StageResultType.DRAW.equals(entry.getValue()))
				.mapToInt(Map.Entry::getKey)
				.toArray();
		final int[] failSides = result.sideResultMap.entrySet().stream()
				.filter(entry -> StageResult.StageResultType.FAIL.equals(entry.getValue()))
				.mapToInt(Map.Entry::getKey)
				.toArray();

		return String.format("[SF] 战斗结束. 胜利方 %s, 失败方 %s, 平局 %s",
				Arrays.toString(successSides),
				Arrays.toString(failSides),
				Arrays.toString(drawSides));
	}
}
